package Chapter2.Comparing.c5;
import java.util.Arrays;
import java.util.Comparator;

public class Sort {
    public static void main(String[] args) {
        int[] arr={3,4,6,7,2,1,9,5};
        int[] arr2={5,6,7,4,4,4,4,5};
        int[] arr3= new int[6];
        System.out.println("排序前数组为：");
        for(int num:arr) {
            System.out.print(num+" ");
        }
        System.out.println("\n"+"-------------------");
        for (int i=0; i<arr.length;i++){
            System.out.print(arr[i]+" ");
        }
        /*//冒泡排序
        for (int a=0; a<arr.length-1; a++) {
            for (int b =0; b<arr.length-1-a;b++){
                if (arr[b]>arr[b+1]) {
                    int temp = arr[b];
                    arr[b]=arr[b+1];
                    arr[b+1]=temp;
                }
            }
        }

        System.out.println();
        System.out.println("冒泡排序后数组为：");
        for(int num:arr){
            System.out.print(num+" ");
        }*/

        //选择排序
        for (int i=0; i<arr.length-1;i++){
            int k = i;
            for(int j=k+1;j<arr.length;j++) {
                if(arr[j]<arr[k]){
                    k=j;
                }
            }

            if(i!=k){
                int temp = arr[i];
                arr[i] = arr[k];
                arr[k]=temp;
            }
        }
        System.out.println();
        System.out.println("选择排序后数组为：");
        for(int num:arr){
            System.out.print(num+" ");
        }
        System.out.println();
        System.out.println(arr.equals(arr2));
        Arrays.fill(arr3,0,5,7);
        Arrays.fill(arr3,5,6,6);
        Arrays.sort(arr3);
        Comparator cmp = new MyComparator();
       // Arrays.sort(arr3. cmp);
        for(int num:arr3){
            System.out.print(num+" ");
        }
    }

}
class  MyComparator implements Comparator<Integer>{


        @Override
        public int compare(Integer o1, Integer o2) {
            if(o1<o2) {
                return 1;
            }else if(o1 > o2) {
                return -1;
            }else {
                return 0;
            }
        }

}
